#!/usr/bin/env node
let obj = {}
let list = [
    {
        question: '请输入用户名：',
        cb(chunk, next) {
            obj.username = chunk.toString().trim()
            next(list)
        }
    },
    {
        question: '请输入邮箱账号：',
        cb(chunk, next) {
            obj.email = chunk.toString().trim()
            next(list)
        }
    },
    {
        question: '请输入密码：',
        cb(chunk) {
            obj.password = chunk.toString().trim()
            console.log(obj)
            process.exit()
        }
    }
]
let index = 0
function next(list) {
    index += 1
    process.stdout.write(list[index].question)
}
const a = (questions = list) => {
    process.stdout.write(questions[index].question)
    process.stdin.on('data', chunk => {
        questions[index].cb(chunk, next)
    })
}
a(list)